#include "alwindow.h"
#include <QPushButton>
#include <QMenuBar>
#include <QLineEdit>
#include <QLabel>
#include <qfont.h>

alwindow::alwindow(QWidget *parent) : QWidget(parent) {
    this->resize(800, 300);
    QFont font;
    font.setPointSize(15);
    QLabel *text_1 = new QLabel("宽度：", this);
    QLabel *text_2 = new QLabel("高度：", this);
    QLabel *text_3 = new QLabel("地雷数量：", this);
    text_1->move(50, 100);
    text_1->setFont(font);
    text_2->move(250, 100);
    text_2->setFont(font);
    text_3->move(450, 100);
    text_3->setFont(font);
    QLineEdit *edit_len = new QLineEdit(this);
    QLineEdit *edit_wid = new QLineEdit(this);
    QLineEdit *edit_num = new QLineEdit(this);
    edit_len->move(50, 150);
    edit_len->resize(150, 40);
    edit_wid->move(250, 150);
    edit_wid->resize(150, 40);    
    edit_num->move(450, 150);
    edit_num->resize(150, 40);
    QPushButton *confirm = new QPushButton("确认", this);
    confirm->move(600, 230);
    confirm->resize(150, 60);
    //-----确认按钮发送信号，返回自定义值-----
    connect(confirm, &QPushButton::clicked, this, [=]() {
        //----防止变量越界----
        length = edit_len->text().toInt();
        if (length > 40) length = 40;
        if (length < 1) length = 1;
        width = edit_wid->text().toInt();
        if (width > 31) width = 31;
        if (width < 1) width = 1;
        num = edit_num->text().toInt();
        if (num < 1) num = 1;
        if (num >= length * width) num = length * width - 1;
        //----返回完成信号，level窗口开始生成游戏界面----
        emit this->finished();
    });
}
